package com.rcl.httpurlconnection;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.rcl.httpurlconnection.activity.ItemListActivity;
import com.rcl.httpurlconnection.activity.PostRequestActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ListView mListView;
    private ArrayAdapter<String> strTitle;
    private List<String> mList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView() {
        mListView = findViewById(R.id.ll_list);
        mList.add("ItemList");
        mList.add("Image");
        mList.add("post请求");
        strTitle = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList);
        mListView.setAdapter(strTitle);

        initEvent();
    }

    private void initEvent() {
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        startActivity(new Intent(MainActivity.this, ItemListActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(MainActivity.this, ImageActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(MainActivity.this, PostRequestActivity.class));
                        break;
                }
            }
        });
    }

}